from mcpi.minecraft import Minecraft, mcpy
from mcpi.vec3 import Vec3
from util.coordinates import mc, RelativeCoordinates
import time


playerName = "xiaole"
player = mc.getPlayer(playerName)
offset = Vec3(-18, 0, -24)
rc = RelativeCoordinates(player, offset)


# 给定两点, 返回范围内的坐标集
def area(x1, y1, x2, y2):
    return [[x, y] for x in range(x1, x2 + 1) for y in range(y1, y2 + 1)]


# X,Y List构成的阵列
def dots(xn, yn):
    return [[x, y] for x in xn for y in yn]


# X,Y List构成的阵列
def dotsxr(xn, yn):
    return [[x, y] for x in filter((lambda n: not n in xn), range(min(xn), max(xn))) for y in yn]


def dotsyr(xn, yn):
    return [[x, y] for x in xn for y in filter((lambda n: not n in yn), range(min(yn), max(yn)))]


# 数据层, List, 每个元素为一层。自下向上建
levelData = [
    ["海晶石", *area(0, 1, 0, 17), *area(1, 0, 28, 18), *area(29, 1, 29, 17)],  # level 0
    [  # level 1
        ["海晶石", *area(0, 1, 0, 17), *area(1, 0, 28, 0), *area(1, 18, 28, 18), *area(17, 19, 20, 23), *area(29, 1, 29, 17)],
        ["磨制闪长岩", *area(2, 2, 27, 16)],
        ["草方块", *area(1, 1, 28, 1), *area(1, 17, 28, 17), *area(1, 2, 1, 16), *area(28, 2, 28, 16), *area(13, 12, 27, 16)],
        ["磨制闪长岩", *area(22, 16, 27, 16), *area(18, 13, 19, 13), *area(18, 15, 19, 15), *area(21, 12, 21, 16)],
        ["水", *area(3, 3, 7, 15), *area(8, 12, 11, 15)],
    ],
    [  # level 2
        ["盛开的杜鹃花丛", *dotsxr([1, 5, 9, 13, 17, 18, 19, 20, 24, 28], [1, 17]), *dotsyr([1, 28], [1, 5, 9, 13, 17]), *area(18, 1, 19, 1)],
        ["去皮橡木原木", *dots([1, 5, 9, 13, 17, 20, 24, 28], [1, 17]), *dots([1, 28], [5, 9, 13])],
        ["玫瑰丛", *area(22, 12, 26, 15)],
        ["深色橡木栅栏", [14, 14]],
        ["石英台阶", [14, 13], [14, 15]],
        ["平滑石英楼梯:2", [15, 13], [15, 15]],
        ["玻璃板", *area(9, 10, 15, 10), *area(22, 10, 26, 10), *area(15, 8, 17, 8), *area(20, 8, 22, 8)],
        ["蓝色染色玻璃", [9, 10], [15, 10], [22, 10], [26, 10]],
        ["青金石块", *area(9, 3, 26, 3), *area(9, 4, 9, 9), *area(15, 6, 15, 9), *area(22, 6, 22, 9), *area(26, 4, 26, 9), [17, 8], [20, 8]],
        ["深色橡木栅栏", [17, 11], [20, 11]],
        # ["平滑石英楼梯:1", [25, 7]],
        # ["平滑石英块", *area(25, 4, 25, 6)],
    ],
    [  # level 3
        ["黑色染色玻璃板", *area(28, 2, 28, 16), *area(1, 2, 1, 16), *area(1, 17, 17, 17), *area(20, 17, 28, 17), *area(1, 1, 28, 1)],
        ["去皮橡木原木", *dots([1, 5, 9, 13, 17, 20, 24, 28], [1, 17]), *dots([1, 28], [5, 9, 13])],
        ["橙色地毯", [14, 14]],
        ["玻璃板", *area(9, 10, 15, 10), *area(22, 10, 26, 10), *area(15, 8, 17, 8), *area(20, 8, 22, 8)],
        ["蓝色染色玻璃", [9, 10], [15, 10], [22, 10], [26, 10]],
        ["青金石块", *area(9, 3, 26, 3), *area(9, 4, 9, 9), *area(15, 6, 15, 9), *area(22, 6, 22, 9), *area(26, 4, 26, 9), [17, 8], [20, 8]],
        ["深色橡木栅栏", [17, 11], [20, 11]],
        # ["平滑石英楼梯:1", [25, 6]],
        # ["平滑石英块", *area(25, 4, 25, 5)],
    ],
    [  # level 4
        ["南瓜灯", *dots([1, 5, 9, 13, 17, 20, 24, 28], [1, 17]), *dots([1, 28], [5, 9, 13])],
        ["玻璃板", *area(9, 10, 15, 10), *area(22, 10, 26, 10), *area(15, 8, 17, 8), *area(20, 8, 22, 8)],
        ["蓝色染色玻璃", [9, 10], [15, 10], [22, 10], [26, 10]],
        ["青金石块", *area(9, 3, 26, 3), *area(9, 4, 9, 9), *area(15, 6, 15, 9), *area(22, 6, 22, 9), *area(26, 4, 26, 9), [17, 8], [20, 8]],
        ["深色橡木栅栏", [17, 11], [20, 11]],
        # ["平滑石英楼梯:1", [25, 5]],
        # ["平滑石英块", [25, 4]],
    ],
    [  # level 4
        ["玻璃板", *area(9, 10, 15, 10), *area(22, 10, 26, 10), *area(15, 8, 17, 8), *area(20, 8, 22, 8)],
        ["蓝色染色玻璃", [9, 10], [15, 10], [22, 10], [26, 10]],
        ["青金石块", *area(9, 3, 26, 3), *area(9, 4, 9, 9), *area(15, 6, 15, 9), *area(22, 6, 22, 9), *area(26, 4, 26, 9), [17, 8], [20, 8]],
        ["深色橡木栅栏", [17, 11], [20, 11]],
        # ["平滑石英楼梯:1", [25, 5]],
        # ["平滑石英块", [25, 4]],
    ],
    [  # level 5
        ["玻璃板", *area(9, 10, 15, 10), *area(22, 10, 26, 10), *area(15, 8, 17, 8), *area(20, 8, 22, 8)],
        ["蓝色染色玻璃", [9, 10], [15, 10], [22, 10], [26, 10]],
        ["青金石块", *area(9, 3, 26, 3), *area(9, 4, 9, 9), *area(15, 4, 22, 8), *area(26, 4, 26, 9), [15, 9], [22, 9]],
        ["深色橡木活板门:3", *area(17, 9, 20, 11)],
        # ["平滑石英楼梯:1", [25, 4]],
    ],
    [  # level 6
        ["金块", *area(8, 2, 16, 11), *area(21, 2, 27, 11), *area(17, 2, 20, 8), *area(13, -2, 22, 1)],
        # ["平滑石英楼梯:1", [25, 3]],
        ["空气", *area(25, 4, 25, 9)],
    ],
    [  # level 7
        ["玻璃板", *area(8, 11, 16, 11), *area(21, 11, 27, 11), *area(16, 8, 21, 8), *area(8, 2, 13, 2), *area(22, 2, 27, 2)],
        ["玻璃板", *area(13, -1, 13, 1), *area(13, -2, 22, -2), *area(22, -1, 22, 1)],
        ["金块", *area(8, 2, 8, 11), *area(27, 2, 27, 11), *area(16, 8, 16, 11), *area(21, 8, 21, 11)],
        # ["平滑石英楼梯:1", [15, 10]],
        # ["平滑石英块", *area(15, 8, 15, 9)],
    ],
    [  # level 7
        ["玻璃板", *area(8, 11, 16, 11), *area(21, 11, 27, 11), *area(16, 8, 21, 8), *area(8, 2, 13, 2), *area(22, 2, 27, 2)],
        ["玻璃板", *area(13, -1, 13, 1), *area(13, -2, 22, -2), *area(22, -1, 22, 1)],
        ["金块", *area(8, 2, 8, 11), *area(27, 2, 27, 11), *area(16, 8, 16, 11), *area(21, 8, 21, 11)],
        # ["平滑石英楼梯:1", [15, 10]],
        # ["平滑石英块", *area(15, 8, 15, 9)],
    ],
    [  # level 7
        ["玻璃板", *area(8, 11, 16, 11), *area(21, 11, 27, 11), *area(16, 8, 21, 8), *area(8, 2, 13, 2), *area(22, 2, 27, 2)],
        # ["玻璃板", *area(13, -1, 13, 1), *area(13, -2, 22, -2), *area(22, -1, 22, 1)],
        ["金块", *area(8, 2, 8, 11), *area(27, 2, 27, 11), *area(16, 8, 16, 11), *area(21, 8, 21, 11)],
        # ["平滑石英楼梯:1", [15, 10]],
        # ["平滑石英块", *area(15, 8, 15, 9)],
    ],
    [  # level 8
        ["玻璃板", *area(8, 11, 16, 11), *area(21, 11, 27, 11), *area(16, 8, 21, 8), *area(8, 2, 13, 2), *area(22, 2, 27, 2)],
        ["金块", *area(8, 2, 8, 11), *area(27, 2, 27, 11), *area(16, 8, 16, 11), *area(21, 8, 21, 11)],
        # ["平滑石英楼梯:1", [15, 9]],
        # ["平滑石英块", [15, 8]],
    ],
    [  # level 9
        ["玻璃板", *area(8, 11, 16, 11), *area(21, 11, 27, 11), *area(16, 8, 21, 8), *area(8, 2, 13, 2), *area(22, 2, 27, 2)],
        ["金块", *area(8, 2, 8, 11), *area(27, 2, 27, 11), *area(16, 8, 16, 11), *area(21, 8, 21, 11)],
        # ["平滑石英楼梯:1", [15, 8]],
    ],
    [  # level 10
        ["金块", *area(8, 2, 16, 11), *area(21, 2, 27, 11), *area(17, 2, 20, 8)],
        # ["平滑石英楼梯:1", [15, 7]],
        ["空气", *area(15, 8, 15, 10)],
    ],
    [  # level 11
        ["钻石块", *area(12, 2, 23, 10)],
        # ["平滑红砂岩楼梯:1", [15, 6]],
        ["空气", *area(15, 7, 15, 9)],
    ],
    [  # level 12
        ["玻璃板", *area(12, 2, 23, 2), *area(12, 10, 23, 10)],
        ["钻石块", *area(12, 2, 12, 10), *area(23, 2, 23, 10)],
    ],
    [  # level 12
        ["玻璃板", *area(12, 2, 23, 2), *area(12, 10, 23, 10)],
        ["钻石块", *area(12, 2, 12, 10), *area(23, 2, 23, 10)],
    ],
    [  # level 12
        ["玻璃板", *area(12, 2, 23, 2), *area(12, 10, 23, 10)],
        ["钻石块", *area(12, 2, 12, 10), *area(23, 2, 23, 10)],
    ],
    [  # level 13
        ["玻璃板", *area(12, 2, 23, 2), *area(12, 10, 23, 10)],
        ["钻石块", *area(12, 2, 12, 10), *area(23, 2, 23, 10)],
    ],
    [  # level 14
        ["玻璃板", *area(12, 2, 23, 2), *area(12, 10, 23, 10)],
        ["钻石块", *area(12, 2, 12, 10), *area(23, 2, 23, 10)],
    ],
    ["钻石块", *area(12, 2, 23, 10)],  # level 15
]


# 用建筑数据层层建造
def build(buildData):
    layer = -2
    for line in buildData:
        items = line if type(line[0]) == list else [line]
        for item in items:
            content = (item[0] + ":0").split(":")
            matrial = content[0]
            matrialData = int(content[1])
            for place in item[1:]:
                rc.setBlock(place[0], layer, place[1], matrial, matrialData)
        layer += 1


build(levelData)
